package com.ruoyi.web.controller.client;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.GetUserId;
import com.ruoyi.common.enums.OperatorType;
import com.ruoyi.common.enums.RequestType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.responseBodyJson.JSON;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.yf.domain.*;
import com.ruoyi.yf.domain.mobile.NoOutBoxInfo;
import com.ruoyi.yf.domain.mobile.ResponseData;
import com.ruoyi.yf.service.IYfDisposeService;
import com.ruoyi.yf.service.IYfTagService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;


// 医废采集APP - 医院装箱 - 处置公司装车
@RequestMapping("/client/yfdispose")
@RestController
public class ClientReportdisposeController extends BaseController {

    @Autowired
    private IYfDisposeService yfDisposeService;

    @Autowired
    private IYfTagService yfTagService;


    // 根据条码获取医废信息
    @ApiOperation(value = "接口-根据条码获取医废信息，不装箱，处置公司巡检")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "codeId", value = "条码", dataType = "String", required = true)
    })
    @RequestMapping(method = RequestMethod.POST, value = "/getYFInfoByYfCode")
    public YfTag getYFInfoByYfCode(String codeId) {
        YfTag yfTag = yfDisposeService.getYFInfoByYfCode(codeId);
        return yfTag;
    }


    // 查询未出库的医废列表
    @ApiOperation(value = "接口-查询已入库的医废列表")
    @RequestMapping(method = RequestMethod.POST, value = "/getNoOutStoreYFlistByStagingId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医院id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "stagingId", value = "暂存点id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "ksId", value = "科室id", dataType = "Long", required = false),
            @ApiImplicitParam(name = "day", value = "日期", dataType = "String", required = false),
    })
    @JSON(type = YfTag.class, include = "codeid,bag,weight,trashStatus,trashType,sourceDeptId,sourceDeptName,nurseId,nurseName,collectUpdateDate")
    public TableDataInfo<List<YfTag>> getNoOutStoreYFlistByStagingId(Long userId, Long hospitalId, Long stagingId, Long ksId, String day) {
        if( userId == null || hospitalId == null || stagingId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfTag> list = yfDisposeService.getNoOutStoreYFlistByStagingId(userId, stagingId, ksId, day);  // 医废状态：10 - 20
        return getDataTable(list);
    }


    // 医废装箱 -- 相当于入库
    @ApiOperation(value = "接口-医废装箱")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "codeId", value = "条码", type = "String", required = true),
            @ApiImplicitParam(name = "boxCode", value = "箱码", type = "Long", required = true),
            @ApiImplicitParam(name = "userId", value = "用户id", type = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医院id", type = "Long", required = true),
            @ApiImplicitParam(name = "stagingId", value = "暂存点id", type = "Long", required = true),
            @ApiImplicitParam(name = "yfType", value = "医废类型", type = "String", required = false)

    })
    @RequestMapping(method = RequestMethod.POST, value = "/yfBoxing")
    @Log(title = "接口-医废装箱", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE,
            requestType = RequestType.KEYVALUE, getUserId = GetUserId.USERID)
    public HashMap<String, Object> yfBoxing(String codeId, String boxCode,
                                            Long userId, Long hospitalId, Long stagingId, String yfType) {
        HashMap<String, Object> hashMap = new HashMap<>();
        if (StringUtils.isEmpty(codeId) || StringUtils.isEmpty(boxCode)
                || userId == null || hospitalId == null || stagingId == null) {
            hashMap.put("resultCode", "N");
            hashMap.put("msg", "参数不能为空");
            return hashMap;
        }
        // 根据条码查询医废
        YfTag yf = yfDisposeService.selectYfTagByCodeId(codeId);
        // 条码无效
        if( yf == null ){
            hashMap.put("resultCode", "0");
            hashMap.put("msg", "条形码无效");
            return hashMap;
        }
        if( !(yf.getHospitalId() + "").equals(hospitalId + "") ){
            hashMap.put("resultCode", "5");
            hashMap.put("msg", "其它医疗机构医废");
            return hashMap;
        }
        // 只有10 -> 20   15、20、25、30
        if( yf.getTrashStatus().equals("15") ){
            hashMap.put("resultCode", "1");
            hashMap.put("msg", "此码已转运");
            return hashMap;
        }else if( yf.getTrashStatus().equals("20") ){
            hashMap.put("resultCode", "2");
            hashMap.put("msg", "此码已装箱");
            return hashMap;
        }else if( yf.getTrashStatus().equals("10") ){
            // 箱内有医废时，上传医废类型判断新装箱医废类型是否一致
            if(!StringUtils.isEmpty(yfType)){
                if( !yfType.equals(yf.getTrashType()) ){
                    hashMap.put("resultCode", "4");
                    hashMap.put("msg", "医废类型不一致");
                    return hashMap;
                }
            }
            // 医废装箱，只有10 -> 20，需要返回
            Date date = new Date();
            yfDisposeService.yfBoxing(codeId, boxCode, userId, date);
            yf.setIntoDateStr(date);
            hashMap.put("resultCode", "Y");
            hashMap.put("msg", "装箱成功");
            hashMap.put("yf",yf);
            return hashMap;
        }else{
            hashMap.put("resultCode", "3");
            hashMap.put("msg", "此码已出库");
            return hashMap;
        }

    }


    // 取消医废装箱
    @ApiOperation(value = "接口-取消医废装箱")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "codeId", value = "条码", type = "String", required = true),
            @ApiImplicitParam(name = "userId", value = "用户id", type = "Long", required = true)
    })
    @RequestMapping(method = RequestMethod.POST, value = "/yfUnBox")
    @Log(title = "接口-取消医废装箱", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE,
            requestType = RequestType.KEYVALUE, getUserId = GetUserId.USERID)
    public ResponseData yfUnBox(String codeId, Long userId) {
        if (StringUtils.isEmpty(codeId) || userId == null) {
            return ResponseData.failureN("参数不能为空");
        }
        // 取消医废装箱，只有20 -> 10
        yfDisposeService.yfUnBox(codeId, userId);
        return ResponseData.successY("取消装箱成功");
    }


    // 根据装箱码查询箱内医废，只需按装箱码查询
    @ApiOperation(value = "接口-根据装箱码查询箱内医废")
    @RequestMapping(method = RequestMethod.POST, value = "/getYFByBoxCode")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医院id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "stagingId", value = "暂存点id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "boxCode", value = "箱码", dataType = "String", required = true)
    })
    @JSON(type = YfTag.class, include = "codeid,isBoxedPrint,bag,weight,trashType,sourceDeptId,sourceDeptName,nurseId,nurseName,intoUserId,intoUserName,intoDateStr")
    public TableDataInfo<List<YfTag>> getYFByBoxCode(Long userId, Long hospitalId, Long stagingId, String boxCode) {
        if( userId == null || hospitalId == null || stagingId == null || StringUtils.isEmpty(boxCode) ){
            return getDataTable(new ArrayList<>());
        }
        List<YfTag> list = yfDisposeService.getYFByBoxCode(userId, hospitalId, stagingId, boxCode);
        return getDataTable(list);
    }


    // 查询未装箱袋数、重量；装箱未出库袋数、重量、箱数
    @ApiOperation(value = "接口-查询未装箱袋数、重量；装箱未出库袋数、重量、箱数")
    @RequestMapping(method = RequestMethod.POST, value = "/getNoOutBoxInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医院id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "stagingId", value = "暂存点id", dataType = "Long", required = true)
    })
    public NoOutBoxInfo getNoOutBoxInfo(Long userId, Long hospitalId, Long stagingId) {
        if( userId == null || hospitalId == null || stagingId == null ){
            return new NoOutBoxInfo();
        }
        // 查询未装箱袋数、重量 - 按暂存点查 - 查状态 10
        // 查询装箱未出库袋数、重量 - 按暂存点查 - 查状态 20
        NoOutBoxInfo noOutBoxInfo = yfDisposeService.getNoOutBoxInfo(userId, hospitalId, stagingId);
        return noOutBoxInfo;
    }


    // 查询已装箱未出库箱子列表
    @ApiOperation(value = "接口-查询已装箱未出库箱子列表")
    @RequestMapping(method = RequestMethod.POST, value = "/getBoxedNoOutBoxList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医院id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "stagingId", value = "暂存点id", dataType = "Long", required = true)
    })
    public TableDataInfo<List<YfBox>> getBoxedNoOutBoxList(Long userId, Long hospitalId, Long stagingId) {
        if( userId == null || hospitalId == null || stagingId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfBox> list = yfDisposeService.getBoxedNoOutBoxList(userId, hospitalId, stagingId);
        return getDataTable(list);
    }


    // 根据箱码查询箱码内统计后再打印
    @ApiOperation(value = "接口-根据箱码查询箱码内统计后再打印")
    @RequestMapping(method = RequestMethod.POST, value = "/getInBoxYFPrintByBoxCode")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "boxCode", value = "箱码", dataType = "String", required = true),
            @ApiImplicitParam(name = "status", value = "状态", dataType = "String", required = true),
    })
    public YfBox getInBoxYFPrintByBoxCode(Long userId, String boxCode, String status) {
        if( userId == null || StringUtils.isEmpty(boxCode) ){
            return new YfBox();
        }
        // 0 未封箱，先封箱     1 已封箱 重复打印
        if(status.equals("0")){
            Date date = new Date();
            yfDisposeService.sealingBox(userId, boxCode, date);
        }
        return yfDisposeService.getInBoxYFPrintByBoxCode(userId, boxCode);
    }


    // 根据暂存点id获取未装箱医废
    @ApiOperation(value = "接口-根据暂存点id获取未装箱医废")
    @RequestMapping(method = RequestMethod.POST, value = "/getNoBoxedYFByStagingId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医院id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "stagingId", value = "暂存点id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "ksId", value = "科室id", dataType = "Long", required = false),
            @ApiImplicitParam(name = "day", value = "日期", dataType = "String", required = false),
    })
    @JSON(type = YfTag.class, include = "codeid,bag,weight,trashStatus,trashType,sourceDeptId,sourceDeptName,nurseId,nurseName,collectUpdateDate")
    public TableDataInfo<List<YfTag>> getNoBoxedYFByStagingId(Long userId, Long hospitalId, Long stagingId, Long ksId, String day) {
        if( userId == null || hospitalId == null || stagingId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfTag> list = yfDisposeService.getNoBoxedYFByStagingId(userId, stagingId, ksId, day);  // 医废状态：10  收集未装箱
        return getDataTable(list);
    }


    // 查询封箱未装车箱子列表
    @ApiOperation(value = "接口-查询封箱未装车箱子列表")
    @RequestMapping(method = RequestMethod.POST, value = "/getSealingBoxedNoOutBoxList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医院id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "stagingId", value = "暂存点id", dataType = "Long", required = true)
    })
    public TableDataInfo<List<YfBox>> getSealingBoxedNoOutBoxList(Long userId, Long hospitalId, Long stagingId) {
        if( userId == null || hospitalId == null || stagingId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfBox> list = yfDisposeService.getSealingBoxedNoOutBoxList(userId, hospitalId, stagingId);
        return getDataTable(list);
    }


    // 按暂存点查询当天出库箱子列表
    @ApiOperation(value = "接口-按暂存点查询当天出库箱子列表")
    @RequestMapping(method = RequestMethod.POST, value = "/getTodayOutYFBoxList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医院id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "stagingId", value = "暂存点id", dataType = "Long", required = true)
    })
    public TableDataInfo<List<YfBox>> getTodayOutYFBoxList(Long userId, Long hospitalId, Long stagingId) {
        if( userId == null || hospitalId == null || stagingId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfBox> list = yfDisposeService.getTodayOutYFBoxList(userId, hospitalId, stagingId);
        return getDataTable(list);
    }


    // 获取医废车列表
    @ApiOperation(value = "接口-获取医废车列表")
    @RequestMapping(method = RequestMethod.POST, value = "/getYFTruckList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalParentId", value = "处置公司上级机构id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true)
    })
    public TableDataInfo<List<YfTruck>> getYFTruckList(Long userId, Long disposalParentId, Long disposalId) {
        if( userId == null || disposalParentId == null || disposalId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfTruck> list = yfDisposeService.getYFTruckList(userId, disposalId);
        return getDataTable(list);
    }


    // 按医废车及押运员查询当天装车箱子列表
    @ApiOperation(value = "接口-按医废车及押运员查询当天装车箱子列表")
    @RequestMapping(method = RequestMethod.POST, value = "/getTodayTruckedYFBoxList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "truckId", value = "医废车id", dataType = "Long", required = true)
    })
    public TableDataInfo<List<YfBox>> getTodayTruckedYFBoxList(Long userId, Long disposalId, Long truckId) {
        if( userId == null || disposalId == null || truckId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfBox> list = yfDisposeService.getTodayTruckedYFBoxList(userId, disposalId, truckId);
        return getDataTable(list);
    }


    // 取消医废箱装车
    @ApiOperation(value = "接口-取消医废箱装车")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", type = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", type = "Long", required = true),
            @ApiImplicitParam(name = "boxCode", value = "箱码", type = "String", required = true)
    })
    @RequestMapping(method = RequestMethod.POST, value = "/yfBoxUnTruck")
    @Log(title = "接口-取消医废箱装车", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE,
            requestType = RequestType.KEYVALUE, getUserId = GetUserId.USERID)
    public ResponseData yfBoxUnTruck(Long userId, Long disposalId, String boxCode){
        if (StringUtils.isEmpty(boxCode) || userId == null || disposalId == null){
            return ResponseData.failureN("参数不能为空");
        }
        // 取消医废箱装车，只有30 -> 20
        yfDisposeService.yfBoxUnTruck(userId, disposalId, boxCode);
        return ResponseData.successY("取消装车成功");
    }


    // 医废箱装车 -- 相当于出库
    @ApiOperation(value = "接口-医废箱装车")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", type = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", type = "Long", required = true),
            @ApiImplicitParam(name = "truckId", value = "车辆id", type = "Long", required = true),
            @ApiImplicitParam(name = "boxCode", value = "箱码", type = "Long", required = true)
    })
    @RequestMapping(method = RequestMethod.POST, value = "/yfBoxTrucking")
    @Log(title = "接口-医废箱装车", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE,
            requestType = RequestType.KEYVALUE, getUserId = GetUserId.USERID)
    public HashMap<String, Object> yfBoxTrucking(Long userId, Long disposalId, Long truckId, String boxCode) {
        HashMap<String, Object> hashMap = new HashMap<>();
        if (userId == null || disposalId == null || truckId == null || StringUtils.isEmpty(boxCode)) {
            hashMap.put("resultCode", "N");
            hashMap.put("msg", "参数不能为空");
            return hashMap;
        }
        // 根据箱码查询医废箱
        YfBox box = yfDisposeService.selectYfBoxByBoxCode(boxCode);
        // 条码无效
        if( box == null ){
            hashMap.put("resultCode", "0");
            hashMap.put("msg", "条形码无效");
            return hashMap;
        }
        // 是否封箱
        if(box.getIsBoxedPrint().equals("0")){
            hashMap.put("resultCode", "1");
            hashMap.put("msg", "此箱未封箱");
            return hashMap;
        }
        // 只有20 -> 30   15、20、25、30
        if( box.getTrashStatus().equals("30") ){
            hashMap.put("resultCode", "2");
            hashMap.put("msg", "此箱已装车");
            return hashMap;
        }else if( box.getTrashStatus().equals("20") ){
            // 医废箱装车，只有20 -> 30，需要返回box
            Date date = new Date();
            yfDisposeService.yfBoxTrucking(userId, disposalId, truckId, boxCode, date);
            box.setTruckId(truckId);
            box.setTrashStatus("30");
            box.setOutUserId(userId);
            box.setOutDate(date);
            hashMap.put("resultCode", "Y");
            hashMap.put("msg", "装车成功");
            hashMap.put("box",box);
            return hashMap;
        }else{
            hashMap.put("resultCode", "3");
            hashMap.put("msg", "装车失败");
            return hashMap;
        }
    }


    // 根据条码获取医废信息
    @ApiOperation(value = "接口-根据条码获取医废信息，处置公司巡检，可能是医废袋可能是医废箱")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "codeId", value = "条码", dataType = "String", required = true)
    })
    @RequestMapping(method = RequestMethod.POST, value = "/getHospitalYFInfoByCode")
    public HashMap<String, Object> getHospitalYFInfoByCode(String codeId) {
        HashMap<String, Object> hashMap = new HashMap<>();
        if (codeId == null) {
            hashMap.put("resultCode", "N");
            hashMap.put("msg", "参数不能为空");
            return hashMap;
        }
        // 可能是医废袋，可能是医废箱   1 医废袋    2 医废箱
        YfTag yfTag = yfDisposeService.getYFInfoByYfCode(codeId);
        if( yfTag != null && !StringUtils.isEmpty(yfTag.getCodeid()) ){
            hashMap.put("resultCode", "1");
            hashMap.put("msg", "查询成功");
            hashMap.put("bag",yfTag);
            return hashMap;
        }else{
            YfBox yfBox = yfDisposeService.getYFBoxInfoByBoxCode(codeId);
            if( yfBox != null && !StringUtils.isEmpty(yfBox.getBoxCode()) ){
                hashMap.put("resultCode", "2");
                hashMap.put("msg", "查询成功");
                hashMap.put("box",yfBox);
                return hashMap;
            }else{
                hashMap.put("resultCode", "N");
                hashMap.put("msg", "未查询到医废");
                return hashMap;
            }
        }

    }


    // 扫描诊所科室码查询诊所及科室信息
    @ApiOperation(value = "接口-扫描诊所科室码查询诊所及科室信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "codeId", value = "条码", dataType = "String", required = true)
    })
    @RequestMapping(method = RequestMethod.POST, value = "/getDeptInfoByScanCode")
    public YfDept getDeptInfoByScanCode(String deptId) {
        if (deptId == null) {
            return new YfDept();
        }
        YfDept dept = yfDisposeService.getDeptInfoByScanCode(deptId);
        if(dept == null || dept.getDeptId() == null){
            return new YfDept();
        }
        return dept;
    }


    // 查询当天处置公司去诊所收集医废汇总
    @ApiOperation(value = "接口-查询当天处置公司去诊所收集医废汇总")
    @RequestMapping(method = RequestMethod.POST, value = "/getCZTodayClinicYFTotal")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true)
    })
    public TableDataInfo<List<YfClinic>> getCZTodayClinicYFTotal(Long userId, Long disposalId) {
        if( userId == null || disposalId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfClinic> list = yfDisposeService.getCZTodayClinicYFTotal(userId, disposalId);
        return getDataTable(list);
    }


    // 获取当前用户收集未装箱装车医废列表
    @ApiOperation(value = "接口-获取当前用户收集未装箱装车医废列表")
    @RequestMapping(method = RequestMethod.POST, value = "/getCollNoTruckYFByCollUserId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "yftype", value = "医废类型", dataType = "String", required = false)
    })
    @JSON(type = YfTag.class, include = "codeid,hospitalId,hospitalName,bag,weight,trashType,sourceDeptId,sourceDeptName,collectUpdateDate")
    public TableDataInfo<List<YfTag>> getCollNoTruckYFByCollUserId(Long userId, Long disposalId, String yftype) {
        if( userId == null || disposalId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfTag> list = yfDisposeService.getCollNoTruckYFByCollUserId(userId, disposalId, yftype);
        return getDataTable(list);
    }


    // 接口 - 诊所医废封箱打印
    @ApiOperation(value = "接口-诊所医废封箱打印")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", type = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "truckId", value = "车辆id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "boxCode", value = "箱码", dataType = "String", required = true),
            @ApiImplicitParam(name = "yfjson", value = "出库医废json", dataType = "String", required = true),
    })
    @RequestMapping(method = RequestMethod.POST, value = "/saveCollToTruckYFlist")
    @Log(title = "接口-诊所医废封箱打印", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE,
            requestType = RequestType.KEYVALUE, getUserId = GetUserId.USERID)
    public HashMap<String, Object> saveCollToTruckYFlist(Long userId, Long disposalId, Long truckId, String boxCode, String yfjson) {
        HashMap<String, Object> hashMap = new HashMap<>();
        if( userId == null || disposalId == null || truckId == null || StringUtils.isEmpty(boxCode)
                || StringUtils.isEmpty(yfjson) ){
            hashMap.put("resultCode", "N");
            hashMap.put("msg", "参数不能为空");
            return hashMap;
        }
        // json转list
        List<YfTag> yfList = JSONObject.parseArray(yfjson, YfTag.class);
        int i = 0;
        Date date = new Date();
        if( yfList != null && !yfList.isEmpty() ){
            i = yfDisposeService.saveCollToTruckYFlist(yfList, userId, disposalId, truckId, boxCode, date);
        }
        if (i < 0) {
            hashMap.put("resultCode", "N");
            hashMap.put("msg", "封箱装车失败");
            return hashMap;
        }
        hashMap.put("resultCode", "Y");
        hashMap.put("msg", "封箱装车成功");
        hashMap.put("boxedDateStr", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
        return hashMap;
    }


    // 查询处置公司去诊所收医废未装箱汇总及今天封箱汇总
    @ApiOperation(value = "接口-查询处置公司去诊所收医废未装箱汇总及今天封箱汇总")
    @RequestMapping(method = RequestMethod.POST, value = "/getCZClinicBoxYFTotal")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true)
    })
    public NoOutBoxInfo getCZClinicBoxYFTotal(Long userId, Long disposalId) {
        if( userId == null || disposalId == null){
            return new NoOutBoxInfo();
        }
        NoOutBoxInfo noOutBoxInfo = yfDisposeService.getCZClinicBoxYFTotal(userId, disposalId);
        return noOutBoxInfo;
    }


    // 查询诊所收集未装箱医废列表 - 重复打印
    @ApiOperation(value = "接口-查询诊所收集未装箱医废列表")
    @RequestMapping(method = RequestMethod.POST, value = "/getClinicCollYF")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "ksId", value = "科室id", dataType = "Long", required = false),
            @ApiImplicitParam(name = "day", value = "日期", dataType = "String", required = false),
    })
    @JSON(type = YfTag.class, include = "codeid,bag,weight,trashStatus,trashType,hospitalId,hospitalName,sourceDeptId,sourceDeptName,collectUpdateDate")
    public TableDataInfo<List<YfTag>> getClinicCollYF(Long userId, Long disposalId, Long ksId, String day) {
        if( userId == null || disposalId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfTag> list = yfDisposeService.getClinicCollYF(userId, disposalId, ksId, day);  // 医废状态：10
        return getDataTable(list);
    }


    // 根据押运员查询当天去医院收医废汇总
    @ApiOperation(value = "接口-根据押运员查询当天去医院收医废汇总")
    @RequestMapping(method = RequestMethod.POST, value = "/getCZTodaHospitalYFTotal")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true)
    })
    public TableDataInfo<List<YfBox>> getCZTodaHospitalYFTotal(Long userId, Long disposalId) {
        if( userId == null || disposalId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfBox> list = yfDisposeService.getCZTodaHospitalYFTotal(userId, disposalId);
        return getDataTable(list);
    }


    // 根据押运员查询今日诊所医废封箱列表
    @ApiOperation(value = "接口-根据押运员查询今日诊所医废封箱列表")
    @RequestMapping(method = RequestMethod.POST, value = "/getTodayClinicSealingBoxList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true)
    })
    public TableDataInfo<List<YfBox>> getTodayClinicSealingBoxList(Long userId, Long disposalId) {
        if( userId == null || disposalId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfBox> list = yfDisposeService.getTodayClinicSealingBoxList(userId, disposalId);
        return getDataTable(list);
    }


    // 根据装箱码查询箱内诊所医废
    @ApiOperation(value = "接口-根据装箱码查询箱内诊所医废")
    @RequestMapping(method = RequestMethod.POST, value = "/getClinicYFByBoxCode")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "boxCode", value = "箱码", dataType = "String", required = true)
    })
    @JSON(type = YfTag.class, include = "codeid,isBoxedPrint,bag,weight,trashType,hospitalId,hospitalName,sourceDeptId,sourceDeptName,outDateStr")
    public TableDataInfo<List<YfTag>> getClinicYFByBoxCode(Long userId, Long disposalId, String boxCode) {
        if( userId == null || disposalId == null || StringUtils.isEmpty(boxCode) ){
            return getDataTable(new ArrayList<>());
        }
        List<YfTag> list = yfDisposeService.getClinicYFByBoxCode(userId, disposalId, boxCode);
        return getDataTable(list);
    }


    // 根据押运员查询今天装车医废箱列表
    @ApiOperation(value = "接口-根据押运员查询今天装车医废箱列表")
    @RequestMapping(method = RequestMethod.POST, value = "/getTodayTruckYFBoxListByUserId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医院id", dataType = "Long", required = true)
    })
    public TableDataInfo<List<YfBox>> getTodayTruckYFBoxListByUserId(Long userId, Long disposalId, Long hospitalId) {
        if( userId == null || disposalId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfBox> list = yfDisposeService.getTodayTruckYFBoxListByUserId(userId, disposalId, hospitalId);
        return getDataTable(list);
    }


    // 获取押运员今日诊所收集医废汇总及报零
    @ApiOperation(value = "接口-获取押运员今日诊所收集医废汇总及报零")
    @RequestMapping(method = RequestMethod.POST, value = "/getClinicTodayYFTotalAndZeroByCollUserId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true)
    })
    public TableDataInfo<List<YfBox>> getClinicTodayYFTotalAndZeroByCollUserId(Long userId, Long disposalId) {
        if( userId == null || disposalId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfBox> list = yfDisposeService.getClinicTodayYFTotalAndZeroByCollUserId(userId, disposalId);
        return getDataTable(list);
    }


    // 医疗机构报零
    @ApiOperation(value = "接口-医疗机构报零")
    @RequestMapping(method = RequestMethod.POST, value = "/ClinicCollZeroByUserId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "userName", value = "用户名", dataType = "String", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医疗机构id", dataType = "Long", required = true)
    })
    public HashMap<String, Object> ClinicCollZeroByUserId(Long userId, String userName, Long disposalId, Long hospitalId) {
        HashMap<String, Object> hashMap = new HashMap<>();
        if( userId == null || StringUtils.isEmpty(userName) || disposalId == null || hospitalId == null ){
            hashMap.put("resultCode", "N");
            hashMap.put("msg", "参数不能为空");
            return hashMap;
        }
        try {
            yfDisposeService.ClinicCollZeroByUserId(userId, userName, disposalId, hospitalId);
        } catch (DuplicateKeyException e) {
            // 主键冲突异常 , 该医疗机构当天已报零
            logger.debug(" --- 医疗机构 : " + hospitalId + " 当天已报零!");
            hashMap.put("resultCode", "1");
            hashMap.put("msg", "该医疗机构已报零");
            return hashMap;
        }
        hashMap.put("resultCode", "Y");
        hashMap.put("msg", "上传成功");
        return hashMap;
    }


    // 根据医院医废箱码查询箱内医废
    @ApiOperation(value = "接口-根据医院医废箱码查询箱内医废")
    @RequestMapping(method = RequestMethod.POST, value = "/getHospitalBoxYFListByBoxCode")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "boxCode", value = "箱码", dataType = "String", required = true)
    })
    @JSON(type = YfTag.class, include = "codeid,bag,weight,trashType,trashTypeName,sourceDeptId,sourceDeptName,intoDateStr")
    public TableDataInfo<List<YfTag>> getHospitalBoxYFListByBoxCode(Long userId, Long disposalId, String boxCode) {
        if( userId == null || disposalId == null || StringUtils.isEmpty(boxCode) ){
            return getDataTable(new ArrayList<>());
        }
        List<YfTag> list = yfDisposeService.getHospitalBoxYFListByBoxCode(userId, disposalId, boxCode);
        return getDataTable(list);
    }


    // 根据扫描二维码查询医院信息
    @ApiOperation(value = "接口-根据扫描二维码查询医院信息")
    @RequestMapping(method = RequestMethod.POST, value = "/getHospitalByhospitalId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医院id", dataType = "Long", required = true)
    })
    public YfBox getHospitalByhospitalId(Long userId, Long disposalId, Long hospitalId) {
        if( userId == null || disposalId == null || hospitalId == null ){
            return new YfBox();
        }
        YfBox box = yfDisposeService.getHospitalByhospitalId(hospitalId);
        if(box == null || box.getHospitalId() == null || StringUtils.isEmpty(box.getHospitalName())){
            return new YfBox();
        }
        return box;
    }


    // 查询医院未装车医废箱列表
    @ApiOperation(value = "接口-查询医院未装车医废箱列表")
    @RequestMapping(method = RequestMethod.POST, value = "/getHospitalNoTruckYFBoxList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医院id", dataType = "Long", required = true)
    })
    public TableDataInfo<List<YfBox>> getHospitalNoTruckYFBoxList(Long userId, Long disposalId, Long hospitalId) {
        if( userId == null || disposalId == null  || hospitalId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfBox> list = yfDisposeService.getHospitalNoTruckYFBoxList(userId, disposalId, hospitalId);
        return getDataTable(list);
    }


    // 查询医院已收集未装箱医废
    @ApiOperation(value = "接口-查询医院已收集未装箱医废")
    @RequestMapping(method = RequestMethod.POST, value = "/getCollNoBoxYFByHospitalId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医院id", dataType = "Long", required = true)
    })
    public TableDataInfo<List<YfTag>> getCollNoBoxYFByHospitalId(Long userId, Long disposalId, Long hospitalId) {
        if( userId == null || disposalId == null  || hospitalId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfTag> list = yfDisposeService.getCollNoBoxYFByHospitalId(userId, disposalId, hospitalId);
        return getDataTable(list);
    }


    // 查询诊所今日收集医废
    @ApiOperation(value = "接口-查询诊所今日收集医废")
    @RequestMapping(method = RequestMethod.POST, value = "/getClinicTodayYFListByClinicId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医院id", dataType = "Long", required = true)
    })
    @JSON(type = YfTag.class, include = "codeid,bag,weight,trashStatus,trashType,sourceDeptId,sourceDeptName,collectUpdateDate,outDateStr")
    public TableDataInfo<List<YfTag>> getClinicTodayYFListByClinicId(Long userId, Long disposalId, Long hospitalId) {
        if( userId == null || disposalId == null  || hospitalId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfTag> list = yfDisposeService.getClinicTodayYFListByClinicId(userId, disposalId, hospitalId);
        return getDataTable(list);
    }


    // 诊所医废装箱装车 -- 相当于 收集 -> 出库
    @ApiOperation(value = "接口-诊所医废装箱装车")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", type = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", type = "Long", required = true),
            @ApiImplicitParam(name = "codeId", value = "条码", type = "String", required = true),
            @ApiImplicitParam(name = "boxCode", value = "箱码", type = "Long", required = true),
            @ApiImplicitParam(name = "truckId", value = "医废车id", type = "Long", required = true),
            @ApiImplicitParam(name = "yfType", value = "医废类型", type = "String", required = false)

    })
    @RequestMapping(method = RequestMethod.POST, value = "/clinicYFBoxingAndTrucking")
    @Log(title = "接口-诊所医废装箱装车", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE,
            requestType = RequestType.KEYVALUE, getUserId = GetUserId.USERID)
    public HashMap<String, Object> clinicYFBoxingAndTrucking(Long userId, Long disposalId, Long truckId,
                                                             String codeId, String boxCode,String yfType) {
        HashMap<String, Object> hashMap = new HashMap<>();
        if ( userId == null || disposalId == null || truckId == null ||
                StringUtils.isEmpty(codeId) || StringUtils.isEmpty(boxCode) ) {
            hashMap.put("resultCode", "N");
            hashMap.put("msg", "参数不能为空");
            return hashMap;
        }
        // 根据条码查询医废
        YfTag yf = yfDisposeService.selectYfTagByCodeId(codeId);
        // 条码无效
        if( yf == null ){
            hashMap.put("resultCode", "0");
            hashMap.put("msg", "条形码无效");
            return hashMap;
        }
        // 只有10 -> 30   15、20、25、30
        if( yf.getTrashStatus().equals("15") ){
            hashMap.put("resultCode", "1");
            hashMap.put("msg", "此码已转运");
            return hashMap;
        }else if( yf.getTrashStatus().equals("10") ){
            // 箱内有医废时，判断上传医废类型与新装箱医废类型是否一致
            if(!StringUtils.isEmpty(yfType)){
                if( !yfType.equals(yf.getTrashType()) ){
                    hashMap.put("resultCode", "4");
                    hashMap.put("msg", "医废类型不一致");
                    return hashMap;
                }
            }
            // 医废装箱，只有10 -> 20，需要返回
            Date date = new Date();
            yfDisposeService.clinicYFBoxingAndTrucking(codeId, boxCode, userId, disposalId, truckId, date);
            yf.setOutDateStr(date);
            hashMap.put("resultCode", "Y");
            hashMap.put("msg", "装箱成功");
            hashMap.put("yf",yf);
            return hashMap;
        }else{
            hashMap.put("resultCode", "2");
            hashMap.put("msg", "此码已装箱");
            return hashMap;
        }
    }


    // 取消诊所医废装箱
    @ApiOperation(value = "接口-取消诊所医废装箱")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "codeId", value = "条码", type = "String", required = true),
            @ApiImplicitParam(name = "userId", value = "用户id", type = "Long", required = true)
    })
    @RequestMapping(method = RequestMethod.POST, value = "/clinicYFUnBox")
    @Log(title = "接口-取消诊所医废装箱", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE,
            requestType = RequestType.KEYVALUE, getUserId = GetUserId.USERID)
    public ResponseData clinicYFUnBox(String codeId, Long userId) {
        if (StringUtils.isEmpty(codeId) || userId == null) {
            return ResponseData.failureN("参数不能为空");
        }
        // 取消诊所医废装箱，只有30 -> 10
        yfDisposeService.clinicYFUnBox(codeId, userId);
        return ResponseData.successY("取消装箱成功");
    }


    // 查询诊所今日已装箱及全部未封箱医废箱列表
    @ApiOperation(value = "接口-查询诊所今日已装箱及全部未封箱医废箱列表")
    @RequestMapping(method = RequestMethod.POST, value = "/getClinicTodayBoxedYFAndNoSealingBoxList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "truckId", value = "医废车id", dataType = "Long", required = true)
    })
    public TableDataInfo<List<YfBox>> getClinicTodayBoxedYFAndNoSealingBoxList(Long userId, Long disposalId, Long truckId) {
        if( userId == null || disposalId == null || truckId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfBox> list = yfDisposeService.getClinicTodayBoxedYFAndNoSealingBoxList(userId, disposalId, truckId);
        return getDataTable(list);
    }


    // 根据押运员查询当天去诊所装箱医废汇总
    @ApiOperation(value = "接口-根据押运员查询当天去诊所装箱医废汇总")
    @RequestMapping(method = RequestMethod.POST, value = "/getCZClinicTodaYFTotal")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true)
    })
    public NoOutBoxInfo getCZClinicTodaYFTotal(Long userId, Long disposalId) {
        if( userId == null || disposalId == null ){
            return new NoOutBoxInfo();
        }
        return yfDisposeService.getCZClinicTodaYFTotal(userId, disposalId);
    }


    // 查询诊所未装箱医废列表
    @ApiOperation(value = "接口-查询诊所未装箱医废列表")
    @RequestMapping(method = RequestMethod.POST, value = "/getClinicNoTruckYFList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医院id", dataType = "Long", required = true)
    })
    @JSON(type = YfTag.class, include = "codeid,bag,weight,trashType,sourceDeptId,sourceDeptName,collectUpdateDate")
    public TableDataInfo<List<YfTag>> getClinicNoTruckYFList(Long userId, Long disposalId, Long hospitalId) {
        if( userId == null || disposalId == null  || hospitalId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfTag> list = yfDisposeService.getClinicNoTruckYFList(userId, disposalId, hospitalId);
        return getDataTable(list);
    }


    // 获取押运员今日诊所装箱医废汇总及报零
    @ApiOperation(value = "接口-获取押运员今日诊所装箱医废汇总及报零")
    @RequestMapping(method = RequestMethod.POST, value = "/getClinicTodayBoxedYFTotalAndZero")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true)
    })
    public TableDataInfo<List<YfBox>> getClinicTodayBoxedYFTotalAndZero(Long userId, Long disposalId) {
        if( userId == null || disposalId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfBox> list = yfDisposeService.getClinicTodayBoxedYFTotalAndZero(userId, disposalId);
        return getDataTable(list);
    }


    // 根据押运员查询诊所今日装箱医废
    @ApiOperation(value = "接口-根据押运员查询诊所今日装箱医废")
    @RequestMapping(method = RequestMethod.POST, value = "/getClinicTodayOutYFListByClinicId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医院id", dataType = "Long", required = true)
    })
    @JSON(type = YfTag.class, include = "codeid,bag,weight,trashType,sourceDeptId,sourceDeptName,outDateStr")
    public TableDataInfo<List<YfTag>> getClinicTodayOutYFListByClinicId(Long userId, Long disposalId, Long hospitalId) {
        if( userId == null || disposalId == null  || hospitalId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfTag> list = yfDisposeService.getClinicTodayOutYFListByClinicId(userId, disposalId, hospitalId);
        return getDataTable(list);
    }


    // 根据扫码查询医院信息
    @ApiOperation(value = "接口-根据扫码查询医院信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "code", value = "条码", dataType = "String", required = true)
    })
    @RequestMapping(method = RequestMethod.POST, value = "/getHospitalInfoByScanCode")
    public YfDept getHospitalInfoByScanCode(Long userId, String code) {
        if (userId == null || StringUtils.isEmpty(code)) {
            return new YfDept();
        }
        // 扫码有可能是医院码或科室码
        YfDept dept = yfDisposeService.getHospitalInfoByHospitalId(userId, code);
        if(dept == null || dept.getHospitalId() == null || StringUtils.isEmpty(dept.getHospitalName()) ){
            dept = yfDisposeService.getDeptInfoByScanCode(code);
            if(dept == null || dept.getHospitalId() == null || StringUtils.isEmpty(dept.getHospitalName()) ){
                return new YfDept();
            }
        }
        return dept;
    }


    // 查看医院医废出库量
    @ApiOperation(value = "接口-查看医院医废出库量")
    @RequestMapping(method = RequestMethod.POST, value = "/getHospitalYFOutTotal")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医疗机构id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "startDate", value = "开始时间", dataType = "String", required = true),
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "String", required = true)
    })
    public TableDataInfo<List<YfBox>> getHospitalYFOutTotal(Long userId, Long disposalId, Long hospitalId,
                                                            String startDate, String endDate) {
        if( userId == null || disposalId == null  || hospitalId == null
                || StringUtils.isEmpty(startDate) || StringUtils.isEmpty(endDate) ){
            return getDataTable(new ArrayList<>());
        }
        List<YfBox> list = yfDisposeService.getHospitalYFOutTotal(userId, disposalId, hospitalId, startDate, endDate);
        return getDataTable(list);
    }


    // 根据二维码查询医废车
    @ApiOperation(value = "接口-根据二维码查询医废车")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "truckId", value = "医废车id", dataType = "String", required = true)
    })
    @RequestMapping(method = RequestMethod.POST, value = "/getTruckByCode")
    public YfTruck getTruckByCode(Long userId, Long disposalId, String truckId) {
        if (userId == null || disposalId == null || StringUtils.isEmpty(truckId)) {
            return new YfTruck();
        }
        return yfDisposeService.getTruckByCode(userId, disposalId, truckId);
    }


    // 根据二维码查询押运员
    @ApiOperation(value = "接口-根据二维码查询押运员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "truckerId", value = "押运员id", dataType = "Long", required = true)
    })
    @RequestMapping(method = RequestMethod.POST, value = "/getTruckerByCode")
    public SysUser getTruckerByCode(Long userId, Long disposalId, Long truckerId) {
        if (userId == null || disposalId == null || truckerId == null ) {
            return new SysUser();
        }
        return yfDisposeService.getTruckerByCode(userId, disposalId, truckerId);
    }


    // 入库 -> 出库装车
    @ApiOperation(value = "接口-医废入库->出库装车")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "codeId", value = "条码", type = "String", required = true),
            @ApiImplicitParam(name = "userId", value = "用户id", type = "Long", required = true),
            @ApiImplicitParam(name = "truckId", value = "医废车id", type = "Long", required = true),
            @ApiImplicitParam(name = "truckerId", value = "押运员id", type = "Long", required = true)
    })
    @RequestMapping(method = RequestMethod.POST, value = "/inStoreToOutStoreToTruckYF")
    @Log(title = "接口-医废入库->出库装车", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE,
            requestType = RequestType.KEYVALUE, getUserId = GetUserId.USERID)
    public HashMap<String, Object> inStoreToOutStoreToTruckYF(String codeId, Long userId, Long truckId, Long truckerId) {
        HashMap<String, Object> hashMap = new HashMap<>();
        if ( StringUtils.isEmpty(codeId) || userId == null || truckId == null || truckerId == null ) {
            hashMap.put("resultCode", "N");
            hashMap.put("msg", "参数不能为空");
            return hashMap;
        }
        // 只有已入库状态才能修改成已出库状态
        yfDisposeService.inStoreToOutStoreToTruckYF(codeId, userId, truckId, truckerId );
        hashMap.put("resultCode", "Y");
        hashMap.put("msg", "出库成功");
        return hashMap;
    }


    // 一键出库装车  入库 -> 出库装车
    @ApiOperation(value = "接口-一键出库装车：入库->出库装车")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stagingId", value = "暂存点id", type = "Long", required = true),
            @ApiImplicitParam(name = "userId", value = "用户id", type = "Long", required = true),
            @ApiImplicitParam(name = "truckId", value = "医废车id", type = "Long", required = true),
            @ApiImplicitParam(name = "truckerId", value = "押运员id", type = "Long", required = true)
    })
    @RequestMapping(method = RequestMethod.POST, value = "/oneKeyOutStoreToTruckYF")
    @Log(title = "接口-一键出库装车：入库->出库装车", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE,
            requestType = RequestType.KEYVALUE, getUserId = GetUserId.USERID)
    public HashMap<String, Object> oneKeyOutStoreToTruckYF(Long stagingId, Long userId, Long truckId, Long truckerId) {
        HashMap<String, Object> hashMap = new HashMap<>();
        if ( stagingId == null || userId == null || truckId == null || truckerId == null ) {
            hashMap.put("resultCode", "N");
            hashMap.put("msg", "参数不能为空");
            return hashMap;
        }
        // 只有已入库状态才能修改成已出库状态
        yfDisposeService.oneKeyOutStoreToTruckYF(stagingId, userId, truckId, truckerId );
        hashMap.put("resultCode", "Y");
        hashMap.put("msg", "出库成功");
        return hashMap;
    }


    // 科室医废出库装车 入库 -> 出库
    @ApiOperation(value = "接口-科室医废出库装车：入库->出库 ")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stagingId", value = "暂存点id", type = "Long", required = true),
            @ApiImplicitParam(name = "ksId", value = "科室id", type = "Long", required = true),
            @ApiImplicitParam(name = "userId", value = "用户id", type = "Long", required = true),
            @ApiImplicitParam(name = "truckId", value = "医废车id", type = "Long", required = true),
            @ApiImplicitParam(name = "truckerId", value = "押运员id", type = "Long", required = true)
    })
    @RequestMapping(method = RequestMethod.POST, value = "/oneKSInToOutStoreToTruckYF")
    @Log(title = "接口-科室医废出库装车：入库->出库", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE,
            requestType = RequestType.KEYVALUE, getUserId = GetUserId.USERID)
    public HashMap<String, Object> oneKSInToOutStoreToTruckYF(Long stagingId, Long ksId, Long userId, Long truckId, Long truckerId) {
        HashMap<String, Object> hashMap = new HashMap<>();
        if (stagingId == null || userId == null || truckId == null || truckerId == null ) {
            hashMap.put("resultCode", "N");
            hashMap.put("msg", "参数不能为空");
            return hashMap;
        }
        // 只有指定科室已入库状态才能修改成已出库状态
        yfDisposeService.oneKSInToOutStoreToTruckYF(stagingId, ksId, userId, truckId, truckerId );
        hashMap.put("resultCode", "Y");
        hashMap.put("msg", "出库成功");
        return hashMap;
    }

    // 接口 - 选择出库装车 - 医废出库
    @ApiOperation(value = "接口-选择出库装车-医废出库")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", type = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医院id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "stagingId", value = "暂存点id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "yfjson", value = "出库医废json", dataType = "String", required = true),
            @ApiImplicitParam(name = "truckId", value = "医废车id", type = "Long", required = true),
            @ApiImplicitParam(name = "truckerId", value = "押运员id", type = "Long", required = true)
    })
    @RequestMapping(method = RequestMethod.POST, value = "/saveOutStoreToTruckYFlist")
    @Log(title = "接口-选择出库装车-医废出库", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE,
            requestType = RequestType.KEYVALUE, getUserId = GetUserId.USERID)
    public AjaxResult saveOutStoreToTruckYFlist(Long userId, Long hospitalId, Long stagingId, Long truckId, Long truckerId, String yfjson) {
        if( userId == null || hospitalId == null || stagingId == null || StringUtils.isEmpty(yfjson)
                || truckId == null || truckerId == null ){
            return AjaxResult.error("出库失败！");
        }
        // json转list
        List<YfTag> yfList = JSONObject.parseArray(yfjson, YfTag.class);

        int i = 0;
        if( yfList != null && !yfList.isEmpty() ){
            i = yfDisposeService.saveOutStoreToTruckYFlist(yfList, userId, truckId, truckerId );
        }

        if (i < 0) {
            return AjaxResult.error("出库失败！");
        }
        return AjaxResult.success("出库成功！");
    }


    // 查询1吨医废正负偏差值
    @ApiOperation(value = "接口-查询1吨医废正负偏差值")
    @ApiImplicitParams({
    })
    @RequestMapping(method = RequestMethod.POST, value = "/getOneTonWeightDeviation")
    @Log(title = "接口-医废入库->出库装车", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE,
            requestType = RequestType.KEYVALUE, getUserId = GetUserId.USERID)
    public HashMap<String, Object> getOneTonWeightDeviation() {
        HashMap<String, Object> hashMap = new HashMap<>();
        int weightDeviation = yfDisposeService.getOneTonWeightDeviation();
        hashMap.put("resultCode", "Y");
        hashMap.put("msg", "查询成功");
        hashMap.put("weightDeviation", weightDeviation);
        return hashMap;
    }


    // 扫描医疗机构码查询医疗机构及医废暂存点信息
    @ApiOperation(value = "接口-扫描医疗机构码查询医疗机构及医废暂存点信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "code", value = "条码", dataType = "String", required = true)
    })
    @RequestMapping(method = RequestMethod.POST, value = "/getHospitalAndStagingInfoByScanCode")
    public YfDept getHospitalAndStagingInfoByScanCode(Long userId, String deptId) {
        if (userId == null || StringUtils.isEmpty(deptId)) {
            return new YfDept();
        }
        YfDept dept = yfDisposeService.getHospitalAndStagingInfoByScanCode(userId, deptId);
        return dept;
    }


    // 处置公司批量上传医废接口 -- 批量
    @ApiOperation(value = "接口-提交多条医废")
    @ApiImplicitParam(name = "yfTag", value = "对象", dataType = "YfTag", allowMultiple = true)
    @RequestMapping(method = RequestMethod.POST, value = "/czcompanyBatchSaveYF")
    @Log(title = "接口-提交多条医废", businessType = BusinessType.INSERT, operatorType = OperatorType.MOBILE,
            requestType = RequestType.JSON, getUserId = GetUserId.JSONMOREYFTAG)
    public AjaxResult czcompanyBatchSaveYF(@RequestBody List<YfTag> yflist) {
        int i = 0;
        try{
            i = yfDisposeService.czcompanyBatchSaveYF(yflist);
        }catch (DuplicateKeyException e){   // 301
            return AjaxResult.warn("医废重复上传！");
        }
        if (i < 0){
            return AjaxResult.error("提交失败！");
        }
        return AjaxResult.success("提交成功！");
    }


    // 根据处置公司用户及医废车及医疗机构查询医废(按出库用户)
    @ApiOperation(value = "接口-根据处置公司用户及医废车及医疗机构查询医废(按出库用户)")
    @RequestMapping(method = RequestMethod.POST, value = "/getHospitalTodayYFListByUserAndTruckAndHospital")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "truckId", value = "医废车id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "hospitalId", value = "医院id", dataType = "Long", required = true)
    })
    @JSON(type = YfTag.class, include = "codeid,bag,weight,trashType,outDateStr")
    public TableDataInfo<List<YfTag>> getHospitalTodayYFListByUserAndTruckAndHospital(Long userId, Long disposalId,
                                                                                      Long truckId, Long hospitalId) {
        if (userId == null || disposalId == null || truckId == null ||hospitalId == null) {
            return getDataTable(new ArrayList<>());
        }
        List<YfTag> list = yfDisposeService.getHospitalTodayYFListByUserAndTruckAndHospital(userId, disposalId, truckId, hospitalId);
        return getDataTable(list);
    }


    // 根据押运员查询当天填报医院医废汇总
    @ApiOperation(value = "接口-根据押运员查询当天填报医院医废汇总")
    @RequestMapping(method = RequestMethod.POST, value = "/getCZTBTodayHospitalYFTotal")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true)
    })
    public TableDataInfo<List<YfBox>> getCZTBTodayHospitalYFTotal(Long userId, Long disposalId) {
        if( userId == null || disposalId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfBox> list = yfDisposeService.getCZTBTodayHospitalYFTotal(userId, disposalId);
        return getDataTable(list);
    }


    // 根据押运员及医废车查询医院装车医废列表
    @ApiOperation(value = "接口-根据押运员及医废车查询医院装车医废列表")
    @RequestMapping(method = RequestMethod.POST, value = "/getTodayOneTruckedYFTotalByTruckerFill")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "truckId", value = "车辆id", dataType = "Long", required = true)
    })
    public TableDataInfo<List<YfBox>> getTodayOneTruckedYFTotalByTruckerFill(Long userId, Long disposalId, Long truckId) {
        if( userId == null || disposalId == null || truckId == null ){
            return getDataTable(new ArrayList<>());
        }
        List<YfBox> list = yfDisposeService.getTodayOneTruckedYFTotalByTruckerFill(userId, disposalId, truckId);
        return getDataTable(list);
    }


    // 查询车上未卸车或未转车医废
    @ApiOperation(value = "接口-查询车上未卸车或未转车医废")
    @RequestMapping(method = RequestMethod.POST, value = "/getTruckedYFByTruckId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "truckId", value = "车辆id", dataType = "Long", required = true)
    })
    public YfBox getTruckedYFByTruckId(Long userId, Long disposalId, Long truckId) {
        if( userId == null || disposalId == null || truckId == null ){
            return new YfBox();
        }
        YfBox box = yfDisposeService.getTruckedYFByTruckId(userId, disposalId, truckId);
        return box;
    }



    // 查询车上未卸车或未转车医废详情
    @ApiOperation(value = "接口-查询车上未卸车或未转车医废详情")
    @RequestMapping(method = RequestMethod.POST, value = "/getTruckedYFTotalOrBoxListByTruckId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
            @ApiImplicitParam(name = "truckId", value = "车辆id", dataType = "Long", required = true)
    })
    public HashMap<String, Object> getTruckedYFTotalOrBoxListByTruckId(Long userId, Long disposalId, Long truckId) {
        HashMap<String, Object> hashMap = new HashMap<>();
        if( userId == null || disposalId == null || truckId == null ){
            hashMap.put("resultCode", "N");
            hashMap.put("msg", "参数填写不完整");
            return hashMap;
        }
        // 先查询医废车上未卸车0的医废是否有无箱码的情况，只要有1条按无箱装车处理
        int num = yfDisposeService.getIsTruckYFAllHaveBoxCodeByTruck(userId, disposalId, truckId);
        if( num == 0 ){     // 按都有箱码处理
            List<YfBox> list = yfDisposeService.getTruckedYFTotalOrBoxListByTruckId(userId, disposalId, truckId);
            hashMap.put("resultCode", "1");
            hashMap.put("msg", "查询成功");
            hashMap.put("yfBoxList", list);
            return hashMap;
        }else{  // 按都无箱码处理
            YfBox box = yfDisposeService.getTruckedYFByTruckId(userId, disposalId, truckId);
            hashMap.put("resultCode", "2");
            hashMap.put("msg", "查询成功");
            hashMap.put("yfBox", box);
            return hashMap;
        }
    }


    // 小车剩余医废全部装入医废运输车
    @ApiOperation(value = "接口-小车剩余医废全部装入医废运输车")
    @RequestMapping(method = RequestMethod.POST, value = "/smallTruckYFInBigTruck")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
        @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
        @ApiImplicitParam(name = "smallTruckId", value = "小车id", dataType = "Long", required = true),
        @ApiImplicitParam(name = "bigTruckId", value = "大车id", dataType = "Long", required = true)
    })
    public AjaxResult smallTruckYFInBigTruck(Long userId, Long disposalId, Long smallTruckId, Long bigTruckId) {
        if( userId == null || disposalId == null || smallTruckId == null || bigTruckId == null ){
            return AjaxResult.error("参数不完整");
        }
        yfDisposeService.smallTruckYFInBigTruck(userId, disposalId, smallTruckId, bigTruckId);
        return AjaxResult.success("提交成功！");
    }


    // 按箱小车医废装入大车
    @ApiOperation(value = "接口-按箱小车医废装入大车")
    @RequestMapping(method = RequestMethod.POST, value = "/smallTruckOneBoxYFInBigTruck")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long", required = true),
        @ApiImplicitParam(name = "disposalId", value = "处置公司id", dataType = "Long", required = true),
        @ApiImplicitParam(name = "smallTruckId", value = "小车id", dataType = "Long", required = true),
        @ApiImplicitParam(name = "bigTruckId", value = "大车id", dataType = "Long", required = true),
        @ApiImplicitParam(name = "boxCode", value = "医废箱", dataType = "String", required = true)
    })
    public AjaxResult smallTruckOneBoxYFInBigTruck(Long userId, Long disposalId, Long smallTruckId, Long bigTruckId,
                                                   String boxCode) {
        if( userId == null || disposalId == null || smallTruckId == null
                || bigTruckId == null || StringUtils.isEmpty(boxCode) ){
            return AjaxResult.error("参数不完整");
        }
        yfDisposeService.smallTruckOneBoxYFInBigTruck(userId, disposalId, smallTruckId, bigTruckId, boxCode);
        return AjaxResult.success("提交成功！");
    }

}
